package org.lzh.service;

import org.lzh.dao.TestPaperDao;
import org.lzh.pojo.TestPaper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestPaperService {

    //注入dao
    @Autowired
    protected TestPaperDao testPaperDao;

    //新建问题
    public int insertTestPaper(TestPaper testPaper){
        return testPaperDao.insertTestPaper(testPaper);
    }


    //根据id删除该问题
    public int deleteById(Integer id){
        return testPaperDao.deleteById(id);
    }


    //根据id查找问题
    public TestPaper findById(String id){
        return testPaperDao.findById(id);
    }


    //根据id更新问题
    public int updateById(TestPaper testPaper ){return  testPaperDao.updateById(testPaper);}


    //动态查询所有试卷
    public List<TestPaper> findByDynamic1(TestPaper testPaper){
        return testPaperDao.findByDynamic(testPaper);
    }

    //直接查询全部试卷（不分页）
    public List<TestPaper> findAllTestPaper(){
        return testPaperDao.findAllTestPaper();
    };

    //动态查询所有试卷（分页）
    public List<TestPaper> findByDynamic(TestPaper testPaper,int currPage, int pageSize) {
        //查询全部数据
        List<TestPaper> students = testPaperDao.findByDynamic(testPaper);
        //总数据的长度
        int length=students.size();
        //从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        int lastIndex = currPage * pageSize<length?currPage * pageSize:length;
        return students.subList(firstIndex, lastIndex); //直接在list中截取

    }
}
